package yunwo.cn.yzstation.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;



import java.util.HashMap;
import java.util.List;

import yunwo.cn.yzstation.R;
import yunwo.cn.yzstation.other.PickDialog;


/**
 * Created by Administrator on 2017/2/20.
 */

public class PayTypeAdapter extends BaseAdapter {

    private static final String TAG = "PayTypeAdapter";
    private HashMap<String,String> codeValueMap;
    private List<String> dataList;
    private LayoutInflater inflater;
    private Context context;
    private PickDialog selectPayTypeDialog;
    private TextView textView;
    private boolean isSendGoods;
    public PayTypeAdapter(Context context, List<String> data,  PickDialog selectPayTypeDialog, TextView payTypeTV, boolean isSendGoods) {
        this.codeValueMap = codeValueMap;
        this.dataList = data;
        this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.context = context;
        this.selectPayTypeDialog= selectPayTypeDialog;
        this.textView = payTypeTV;
        this.isSendGoods = isSendGoods;
    }


    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHold hold;
        if(convertView!=null){
             hold = (ViewHold) convertView.getTag();
        }else{
            hold = new ViewHold();
            convertView = inflater.inflate(R.layout.activity_pay_type_item, viewGroup, false);
            hold.payTypeNameTV = (TextView) convertView.findViewById(R.id.payTypeNameTV);
            hold.itemRL = (RelativeLayout) convertView.findViewById(R.id.itemRL);
            convertView.setTag(hold);
        }
        hold.payTypeNameTV.setText(dataList.get(position));
        hold.itemRL.setOnClickListener(new MyItemClick(position));
        return convertView;
    }

    class ViewHold{
        TextView payTypeNameTV;
        RelativeLayout itemRL;
    }

    class MyItemClick implements View.OnClickListener{

        private int position;
        public MyItemClick(int position) {
            this.position = position;
        }

        @Override
        public void onClick(View v) {
            selectPayTypeDialog.dismiss();
            textView.setText(dataList.get(position));
//            String payTypeValue = codeValueMap.get(dataList.get(position));
          /*  if(isSendGoods){
                sendGoodsCache.put("payTypeValue",payTypeValue);
                sendGoodsCache.put("payTypeName",dataList.get(position));
            }else{
                sendGoodsCache.put("receivePayTypeValue",payTypeValue);
                sendGoodsCache.put("receivePayTypeName",dataList.get(position));
            }

            LogUtil.d(TAG,"payTypeValue:"+payTypeValue);*/
        }
    }
}
